home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 40
/
Amiga Format CD40 (1999-05-11)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-06].iso
/
-readerstuff-
/
paul_qureshi
/
info
/
spline2.txt
< prev
next >
Wrap
Text File
|
1999-03-27
|
1KB
|
67 lines
Below is code for a simple fixed point recursive de Casteljau
algorithm. Ive been racking my brains over this one,
but I cant figure out the equivalent array based algo.
-> assumes 16 bit shorts, 32 bit longs
// this one used internally only
void _spline(long *_x, long *_y, byte color, int depth);
// this one called from main, size of x, y should be 4
void spline(short *x, short *y, byte color, int depth)
{
long _x[4], _y[4];
for(int i=0;i<4;i++)
{
_x[i] = long(x[i]) << 16;
_y[i] = long(y[i]) << 16;
}
_spline(_x,_y,color,depth);
}
void _spline(long *_x, long *_y, byte color, int depth)
{
if(depth==0)
{
short x[4], y[4];
for(int i=0;i<4;i++)
{
x[i] = _x[i] >> 16;
y[i] = _y[i] >> 16;
}
polyline(x,y,4,color);
}
else
{
long hx,hy, px[4], py[4], rx[4], ry[4];
px[0] = _x[0]; py[0] = _y[0];
rx[3] = _x[3]; ry[3] = _y[3];
px[1] = (_x[0]+_x[1]) / 2;
py[1] = (_y[0]+_y[1]) / 2;
rx[2] = (_x[2]+_x[3]) / 2;
ry[2] = (_y[2]+_y[3]) / 2;
hx = (_x[1]+_x[2]) / 2;
hy = (_y[1]+_y[2]) / 2;
px[2] = (px[1]+hx) / 2;
py[2] = (py[1]+hy) / 2;
rx[1] = (rx[2]+hx) / 2;
ry[1] = (ry[2]+hy) / 2;
rx[0] = px[3] = (px[2]+rx[1]) / 2;
ry[0] = py[3] = (py[2]+ry[1]) / 2;
_spline(px, py, color, depth-1);
_spline(rx, ry, color, depth-1);
}
}